package com.demo.villageresidence.controller;

import cn.hutool.core.collection.CollUtil;
import com.demo.villageresidence.dto.Result;
import com.demo.villageresidence.service.RemarkService;
import com.demo.villageresidence.service.impl.RemarkServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/echarts")
public class EchartsController {

    @Autowired
    private RemarkService remarkService;

    @GetMapping("/getRemarkCharts")
    public Result getRemarkCharts() {
        Map<String,Object> map = new HashMap<>();
        // 获取当前日期的前七天的数据
        ArrayList<Integer> y = new ArrayList<>();
        ArrayList<LocalDate> x = new ArrayList<>();
        for (int i = 1; i <= 7; i++) {
            // minusDays减去指定的天数
            LocalDate localDate = LocalDate.now().minusDays(i);
            Integer remarkTime = remarkService.query().gt("remark_time", localDate).count();
            x.add(localDate);
            y.add(remarkTime);
        }

        map.put("x", x);
        map.put("y",y);

        return Result.ok(map);
    }

}
